﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace RO___Simulasi_Boarding
{
    public partial class ParamForm : Form
    {
        public string progName;
        public int row, column, betweenTime, group, occupancy;
        public ParamForm()
        {
            InitializeComponent();
        }

        private bool cekTakKosong(string statements)
        {
            if (statements != "") return true;
            else return false;
        }

        private bool cekRow(string statements)
        {
            if (cekTakKosong(statements))
            {
                if(cekAngka(statements))
                    if(cekSelang(int.Parse(statements), 1, 37))
                        return true;
                return false;
            }
            else return false;
        }

        private bool cekColumn(string statements)
        {
            if (cekTakKosong(statements))
            {
                if(cekAngka(statements))
                    if(cekSelang(int.Parse(statements), 1, 6))
                        return true;
                return false;
            }
            else return false;
        }

        private bool cekAntara(string statements)
        {
            if (cekTakKosong(statements))
            {
                if(cekAngka(statements))
                    if(int.Parse(statements) > 0) return true;
                return false;
            }
            else return false;
        }

        private bool cekOkupansi(string statements)
        {
            if (cekTakKosong(statements))
            {
                if (cekAngka(statements))
                    if (cekSelang(int.Parse(statements), 1, 100))
                        return true;
                return false;
            }
            else return false;
        }

        private bool cekAngka(string statements)
        {
            if (statements != "")
            {
                for (int i = 0; i < statements.Length; i++)
                {
                    if (statements[i] < '0' || statements[i] > '9') return false;
                }
                return true;
            }
            return false;
        }

        private bool cekSelang(int data, int min, int max)
        {
            if (data >= min && data <= max) return true;
            else return false;
        }

        private void bt_Confirm_Click(object sender, EventArgs e)
        {
            string message = "";
            if (!cekTakKosong(tb_param1.Text)) message += "Nama Program Belum Diisi.\n";
            if (!cekRow(tb_param2.Text)) message += "Isi Jumlah Baris Antara 1 - 23.\n";
            if (!cekColumn(tb_param3.Text)) message += "Isi Jumlah Kolom Antara 1 - 6.\n";
            if (!cekAntara(tb_param4.Text)) message += "Isi Waktu Antara dengan Angka Positif.\n";
            if (!cekColumn(tb_param5.Text)) message += "Isi Jumlah Grup Antara 1 - 6.\n";
            if (!cekOkupansi(tb_param6.Text)) message += "Isi Okupansi Antara 1 - 100.\n";
            if (message != "")
            {
                MessageBox.Show(message);
                return;
            }
            else
            {
                progName = tb_param1.Text;
                row = int.Parse(tb_param2.Text);
                column = int.Parse(tb_param3.Text);
                betweenTime = int.Parse(tb_param4.Text);
                group = int.Parse(tb_param5.Text);
                occupancy = int.Parse(tb_param6.Text);
                MessageBox.Show("Konfigurasi telah dibuat secara acak.\nUntuk konfigurasi manual, gunakan file konfigurasi\nsesuai format yang ada (*.canv)");
                this.DialogResult = DialogResult.OK;
            }
        }

        private void label11_Click(object sender, EventArgs e)
        {

        }
    }
}
